﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using CoreInmobiliario.Data;

namespace CoreInmobiliario.Business
{
    [DataObject]
    public class Horario
    {
        public static Horario GetInstance()
        {
            return new Horario();
        }

        private static DBDataContext GetDBDataContext()
        {
            Factories.DBDataContextFactory factory = new Factories.DBDataContextFactory();
            return factory.CreateDataContext() as DBDataContext;
        }

        public Data.Horario GetById(int horarioId)
        {
            Data.Horario horario = null;

            using (DBDataContext dataContext = GetDBDataContext())
            {
                try
                {
                    horario = dataContext.Horarios.FirstOrDefault(h => h.HorarioId.Equals(horarioId));
                }
                catch (Exception ex)
                {

                }
            }
            return horario;
        }

        public Boolean UpdateHorarios(Data.Horario h)
        {
            using (DBDataContext dc = GetDBDataContext())
            {
                try
                {
                    Data.Horario horario = dc.Horarios.FirstOrDefault(hs => hs.HorarioId.Equals(h.HorarioId));
                    horario.Descripcion = h.Descripcion;
                    horario.Horario1 = h.Horario1;
                    horario.Horario2 = h.Horario2;
                    horario.Descripcion2 = h.Descripcion2;
                    horario.Horario3 = h.Horario3;

                    dc.SubmitChanges();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
}
